/******************************************************************************
 * Copyright (C) 671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef NODECPP_NET_TCPACCEPTOR_H_
#define NODECPP_NET_TCPACCEPTOR_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <event2/event.h>
#include <event2/listener.h>
#include <NodeCpp/Macros.h>

namespace NodeCpp {
namespace Net {

    class TcpAcceptor
    {
    public:
		typedef void(*AcceptCallback)(evutil_socket_t, struct sockaddr *, int, void *);

        TcpAcceptor(struct event_base *_Base, AcceptCallback _Callback, void *_Userptr = 0);
        ~TcpAcceptor(void);

        bool Open(const char *_Host, int _Port, int _Backlog);
        void Close(void);
        bool Enable(bool _Enable);

    private:
        void _Uninitialize(void);
		static void _AcceptCallback(struct evconnlistener *, evutil_socket_t, struct sockaddr *, int, void *);

        struct event_base *Base_;
        struct evconnlistener* Listener_;
        AcceptCallback Callback_;
        void *UserPtr_;
        DISALLOW_COPY_AND_ASSIGN(TcpAcceptor);
    };

}}

#endif // NODECPP_NET_TCPACCEPTOR_H_
